<template>
  <div>

    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统</el-breadcrumb-item>
      <el-breadcrumb-item>业务系统</el-breadcrumb-item>
    </el-breadcrumb>

    <el-form :inline="true" :model="query" class="query-form" label-width="6rem">
      <el-form-item label="业务编码">
        <el-input v-model="query.sysCode" placeholder="请输入业务编码"></el-input>
      </el-form-item>
      <el-form-item label="业务名称">
        <el-input v-model="query.sysName" placeholder="请输入业务名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onQuery">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onAdd">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table class="table" :data="getSystems" border stripe style="width: 100%">
      <el-table-column prop="sysCode" label="业务编码">
      </el-table-column>
      <el-table-column prop="sysName" label="业务名称">
      </el-table-column>
      <el-table-column label="操作" min-width="60">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <el-pagination class="pagination" background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
    </el-pagination> -->

  </div>
</template>

<style>
.query-form {
  margin-top: 20px;
  padding-top: 25px;
  background-color: #f2f2f2;
}

.table {
  margin-top: 30px;
}

.pagination {
  margin-top: 30px;
  text-align: right;
  padding-right: 2rem;
}
</style>

<script>
import { mapGetters, mapActions } from "vuex";

export default {
  name: "Systems",
  created() {
    console.log("hmx^^^^^^^|created");
    this.reqGetSystems();
  },
  computed: {
    ...mapGetters(["getSystems"])
  },
  data() {
    return {
      query: {
        sysCode: "",
        sysName: ""
      }
    };
  },
  methods: {
    ...mapActions(["reqGetSystems", "reqDeleteSystem"]),
    onQuery() {
      console.log("onQuery!");
    },
    onAdd() {
      console.log("onAdd!");
      this.$router.push({ name: "AddSystem", params: {} });
    },
    handleEdit(index, row) {
      console.log(index);
      console.log(row);
      this.$router.push({
        name: "EditSystem",
        params: {
          _id: row._id,
          sysCode: row.sysCode,
          sysName: row.sysName,
        }
      });
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该业务系统, 是否继续?", "提示", {
        confirmButtonText: "确定",
        confirmButtonClass: "el-button--danger",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.reqDeleteSystem({ _id: row._id });
        })
        .catch(() => {});
    }
  }
};
</script>
